﻿<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <!--    <link href="/static/css/dialog.css" rel="stylesheet"/>-->
    <!--    <script src="/static/js/dialog.js"></script>-->
    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/layui.js"></script>



    <!--开关主键-->
    <script src="/static/bootstrap/bootstrap-switch.js"></script>
    <link href="/static/bootstrap/bootstrap-switch.css" rel="stylesheet"/>

    <!-- PNotify -->
    <script type="text/javascript" src="/static/pnotify/pnotify.js"></script>
    <link href="/static/pnotify/pnotify.css" rel="stylesheet" type="text/css"/>
    <link href="/static/pnotify/pnotify.brighttheme.css" rel="stylesheet" type="text/css"/>

        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}
</head>
<body>
<div class="newtest">

    <div class="container new_serach">

<!--        <form action="{:URL('home/order/index')}" method="get">-->

<!--            <div class="serach_div">-->
<!--                <button class="btn btn-danger btn-sm">筛选</button>-->
<!--            </div>-->
<!--        </form>-->
        <div>
            <button class="btn btn-primary btn-sm" id="add">添加幻灯片</button>
        </div>
    </div>

    <table class="table slide">
        <thead>
        <tr>
            <th scope="col">ID</th>
            <th scope="col">图片</th>
            <th scope="col">排序</th>
            <th scope="col">标题</th>
            <th scope="col">状态</th>
            <th scope="col">操作</th>
        </tr>
        </thead>
        <tbody>
            {volist name="list" id="vo"}
            <tr>
                <td>{$vo.id}</td>
                <td class="slide_thumb">
                    <img src="{$vo.thumb}">
                </td>
                <td>{$vo.sort}</td>
                <td>{$vo.title}</td>
                <td>
                    <input name="status" type="checkbox" data-size="small" data-type="status" value="{$vo.id}" {if condition="$vo['status']==1"} checked {/if} >
                </td>
                <td>
                    <a class="btn btn-primary btn-sm update" data-id="{$vo.id}" >编辑</a>
                </td>
            </tr>
            {/volist}
        </tbody>

    </table>
</div>


</body>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>


<script>

    $('[name="status"]').bootstrapSwitch({
        onText:"启用",
        offText:"禁用",
        onColor:"success",
        offColor:"info",
        size:"small",
        onSwitchChange:function(event,state){
            var ProductId = event.target.defaultValue;
            var type = event.target.dataset.type;
            if (state == true) {
                //上线
                updateProductStatus(ProductId,type,'1');
            } else {
                //下线
                updateProductStatus(ProductId,type,'2');
            }
        }
    });

    //启用禁用
    function updateProductStatus(ProductId,type,status) {
        $.ajax({
            type: "post",
            url: "{:URL('index/System/slideStatus')}",
            data: {id:ProductId,type:type,status:status},
            dataType: "json",
            success: function(data){}
        });
    }

    var modal = new yii.modal();
    $(function() {

        //添加页面
        $("#add").click(function () {
            modal.initialization({
                url: "{:URL('index/System/addSlide')}",
                type: "post",
                data:{
                    type:'detail'
                }
            });
        });

        //修改页面
        $(".update").click(function () {
            let id = $(this).attr("data-id");
            modal.initialization({
                url: "{:URL('index/System/addSlide')}",
                type: "post",
                data:{
                    type:'detail',
                    id:id
                }
            });
        });


    });


    layui.use(['form','jquery','layer','laydate'], function() { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#test6'
            ,range: true
        });


        //统一modal执行保存action
        modal.on("add",function(data){
            var data=$(modal.getid()).find("form").serialize();
            modal.remoteajax({
                url: "{:URL('index/System/doSlide')}",
                type: "post",
                data:data
            });
        });

    });

</script>



</html>
